home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: in2.uu.net!allegra!alice!ark
- From: ark@research.att.com (Andrew Koenig)
- Subject: Re: Arrays or Pointers?
- Message-ID: <DpLq0z.3A8@research.att.com>
- Organization: AT&T Research, Murray Hill NJ
- References: <4kbsk3$f07@zeus.tcp.co.uk> <4kdatp$kcp@grimsel.zurich.ibm.com>
- Date: Tue, 9 Apr 1996 15:36:34 GMT
-
- So far, no one has mentioned what I think is the most important
- difference between arrays+subscripts and pointers: A pointer
- identifies a particular element in a particular array while using
- only a single value. With subscripts, it takes two values: the
- array and the index of the array.
-
- Suppose, for example, that you want to write a function that
- reverses the elements of some part of an array. If you do not
- use pointers, your function needs three arguments: the array,
- the index of the first element, and the index of the last element.
- If you use pointers, the function needs only two arguments.
-
- On the other hand, once you have a pointer to an array element,
- there is no easy way to recover the identity of the array.
-
- Considerations like these are almost always more important
- than sheer speed, which is likely to be compiler-dependent anyway.
- --
- --Andrew Koenig
- ark@research.att.com
-